package com.example.car.vm

import com.example.car.api.CarApiService
import com.example.car.entity.CarPayEntity
import com.example.car.model.CarRepository
import com.example.car.model.CarResultData
import com.example.common.view.vm.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class CarListViewModel @Inject constructor(private val apiService: CarApiService) : BaseViewModel<CarRepository,CarResultData<List<CarPayEntity>>>() {
    fun getCarList(){
        mViewModelScope.launch (mDispatcher){
            try {
                val result = apiService.getCarList()
                mSuccessLiveData.postValue(result)
            } catch (e:Exception){
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}